package com.aacar.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.dto.CouponDto;
import com.aacar.dto.Header;
import com.aacar.interceptor.MemLoginKeyValid;
import com.aacar.service.CouponService;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.CommonVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;

/**
 * 优惠券控制类
 * @author wangh
 *
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private CouponService couponService;
	
	@RequestMapping(value="/validatorCoupon/0",method=RequestMethod.POST)
	@ResponseBody
	@MemLoginKeyValid
	public Object validatorCoupon(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody CouponDto couponDto) {
		logger.info("request:/coupon/validatorCoupon/0" + JSONObject.toJSONString(couponDto));
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		couponDto.setUserId(header.getUserId());//用户id
		Map<String,Object> map  = this.couponService.validatorCoupon(couponDto);//验证券码是否有效
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	}
	
}
